package com.zzyl.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.entity.NursingLevel;
import com.zzyl.entity.NursingProject;
import com.zzyl.mapper.NursingLevelMapper;
import com.zzyl.mapper.NursingProjectMapper;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import com.zzyl.vo.NursingProjectVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description NursingLevelServiceImpl
 * @Author Taoxiuli
 * @Date 2024-09-09
 */
@Service
public class NursingLevelServiceImpl implements NursingLevelService {
    @Autowired
    private NursingLevelMapper nursingLevelMapper;

    @Override
    public List<NursingLevelVo> getListAll() {

        return nursingLevelMapper.getListAll();
    }

    @Override
    public NursingLevelVo getById(Long id) {
        return nursingLevelMapper.getById(id);
    }

    @Override
    public PageResponse<NursingLevelVo> getByPage(String name, Integer status, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        Page<NursingLevel> nursingLevelVos = nursingLevelMapper.selectByPage(name,status);

        PageResponse<NursingLevelVo> levelVoPageResponse = PageResponse.of(nursingLevelVos, NursingLevelVo.class);
        return levelVoPageResponse;
    }

    @Override
    public void addLevel(NursingLevelDto nursingLevelDto) {
        NursingLevel nursingLevel = new NursingLevel();
        BeanUtils.copyProperties(nursingLevelDto,nursingLevel);
        nursingLevelMapper.addLevel(nursingLevel);
    }

    @Override
    public void deleteLevel(Long id) {
        nursingLevelMapper.deleteById(id);
    }

    @Override
    public void updateLevel(NursingLevelDto nursingLevelDto) {
        NursingLevel nursingLevel = new NursingLevel();
        BeanUtils.copyProperties(nursingLevelDto,nursingLevel);
        nursingLevelMapper.update(nursingLevel);
    }

    @Override
    public void updateStatusById(Long id, Integer status) {
        nursingLevelMapper.updateStatusById(id,status);
    }
}
